package io.github.betacatcode.learn.controller;

import io.github.betacatcode.learn.common.Result;
import io.github.betacatcode.learn.form.AuthForm;
import io.github.betacatcode.learn.service.AuthService;
import jakarta.annotation.Resource;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody AuthForm form) {
        return Result.success(authService.doLogin(form));
    }

    @GetMapping("/info")
    public Result<Authentication> info() {
        return Result.success(SecurityContextHolder.getContext().getAuthentication());
    }
}
